package top.jle.jpa.basic.exception;


import com.alibaba.fastjson2.JSONObject;

import java.util.Arrays;


public enum BasicExceptionCode {


    //BASE

    SERVER_ERROR("0.0.0","系统错误"),

    INVALID_PARAM("0.0.1","参数非法"),

    INTERFACE_ERROR("0.0.2","接口访问异常"),

    REPEAT_ERROR("0.0.3","重复访问超限"),

    REQUEST_HEADER_INVALID("0.0.4","请求头部信息缺失"),

    BLACKLIST("0.0.5","判定为黑名单"),

    REPEAT_REQUEST("0.0.6","操作太频繁"),

    DATA_NOT_EXISTS("0.0.7","数据不存在"),
    DATA_DUPLICATE("0.0.8","数据已存在"),

    //AUTH
    AUTH_FAILD("0.1.0","鉴权失败"),

    AUTH_EXPIRED("0.1.1","TOKEN过期"),

    AUTH_EMPTY_TOKEN("0.1.2","TOKEN为空"),

    AUTH_TOKEN_INVALID("0.1.3","TOKEN非法"),

    AUTH_REPEAT_INVALID("0.1.4","TOKEN重复获取"),

    INVALID_SIGNATURE("0.1.5","签名错误"),

    ;

    private final String code;
    private final String name;

    BasicExceptionCode(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static BasicExceptionCode getByCode(String code){
        return Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    public static JSONObject getBasicExceptionCodeDesc(){
        JSONObject json = new JSONObject();
        for(BasicExceptionCode code:BasicExceptionCode.values()){
            json.put(code.getCode(),code.getName());
        }
        return json;
    }

    public String getCode() {
        return code;
    }



    public String getName() {
        return name;
    }


}
